package com.gzx.plugin.tjzy.modular.call.ht.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.plugin.tjzy.modular.call.ht.entity.bo.GzxCallReportBo;
import com.gzx.plugin.tjzy.modular.call.ht.entity.bo.GzxHtCallRecordQueryBo;
import com.gzx.plugin.tjzy.modular.call.ht.entity.vo.GzxCallReportVo;
import com.gzx.plugin.tjzy.modular.call.ht.entity.vo.GzxHtCallRecordVo;
import com.gzx.plugin.tjzy.modular.call.ht.service.GzxHtCallRecordService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;

/**
 * @author zjt
 * @description
 * @date 2024/12/4 17:42
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/tjzy/ht")
public class GzxHtCallRecordController {

    private final GzxHtCallRecordService htCallRecordService;

    /**
     * 话单记录
     *
     * @param callRecordStr
     */
    @PostMapping("/callback/record")
    public void saveHtCallRecord(@RequestBody String callRecordStr) {
        htCallRecordService.saveHtCallRecord(callRecordStr);
    }


    @GetMapping("/setFmPhone")
    public void setFmPhone(@RequestParam("fmPhone") String fmPhone) {
        htCallRecordService.setFmPhone(fmPhone);
    }


    /**
     * 分页查询话单记录
     *
     * @param htCallRecordQueryBo
     */
    @PostMapping("/record/pageList")
    public CommonResult<Page<GzxHtCallRecordVo>> pageList(@RequestBody GzxHtCallRecordQueryBo htCallRecordQueryBo) {
        return CommonResult.data(htCallRecordService.pageList(htCallRecordQueryBo));
    }

    /**
     * 获取当前登录用户的恒天账号
     *
     * @return
     */
    @GetMapping("/getHtAccount")
    public CommonResult<String> getHtAccount() {
        return CommonResult.data(htCallRecordService.getHtAccount());
    }

    /**
     * 获取当前登录用户的恒天账号
     *
     * @return
     */
    @GetMapping("/setCallNumber/{callNumber}")
    public CommonResult<Void> setCallNumber(@PathVariable String callNumber) {
        htCallRecordService.setCallNumber(callNumber);
        return CommonResult.ok();
    }

    /**
     * 获取当前登录用户的恒天账号
     *
     * @return
     */
    @GetMapping("/getCallNumber")
    public CommonResult<String> getCallNumber() {
        return CommonResult.data(htCallRecordService.getCallNumber());
    }

    /**
     * 根据CallId保存当前登录者信息
     *
     * @param callId
     * @return
     */
    @GetMapping("/setCallUser/{callId}")
    public CommonResult<String> setCallUser(@PathVariable("callId") String callId) {
        htCallRecordService.setCallUser(callId);
        return CommonResult.ok();
    }

    /**
     * 发送消息
     *
     * @return
     */
    @GetMapping("/sendMessage")
    public CommonResult<Void> sendMessage() {
        htCallRecordService.sendMessage();
        return CommonResult.ok();
    }

    /**
     * 订阅语音文字消息
     *
     * @return
     */
    @GetMapping("/listen/start/{agentExtNo}")
    public CommonResult<Void> startListen(@PathVariable String agentExtNo) {
        htCallRecordService.startListen(agentExtNo);
        return CommonResult.ok();
    }

    /**
     * 取消订阅语音文字消息
     *
     * @return
     */
    @GetMapping("/listen/stop/{agentExtNo}")
    public CommonResult<Void> stopListen(@PathVariable String agentExtNo) {
        htCallRecordService.stopListen(agentExtNo);
        return CommonResult.ok();
    }

    /**
     * 发送消息
     *
     * @return
     */
    @PostMapping("/callback/voice-to-text")
    public CommonResult<Void> receiveVoiceText(@RequestBody String reqBody) {
        htCallRecordService.receiveVoiceText(reqBody);
        return CommonResult.ok();
    }

    /**
     * 获取通话记录
     *
     * @param bo
     * @return
     */
    @CommonLog("坐席工作报表查询")
    @PostMapping("/call/report/page")
    public CommonResult<Page<GzxCallReportVo>> pageCallReport(@RequestBody GzxCallReportBo bo) {
        return CommonResult.data(htCallRecordService.pageCallReport(bo));
    }

    /**
     * 导出通话记录
     *
     * @param bo
     * @param response
     */
    @GetMapping("/call/report/export")
    public void exportCallReport(GzxCallReportBo bo, HttpServletResponse response) {
        htCallRecordService.exportCallReport(bo, response);
    }
}
